/**
 * Created by Aber on 17/3/23.
 */
// 加载模块
module.exports = function(ngModule) {
    require('./noted.scss');
    ngModule.directive('noted',function () {
        return {
            restrict: 'E',//元素(element)
            scope:  true,
            replace: true,
            template: require('./noted.html'),//模板
            controllerAs: 'noted',// <=> $scope.vm = {greeting: '你好，我是卡哥'}
            controller: function ($scope,$http) {
                //添加模板
                $scope.addNote = function () {
                    sessionStorage.removeItem("notes")
                    layer.open({
                        type: 2,
                        title: '添加笔记',
                        shadeClose: true,
                        shade: 1,
                        area: ['70%', '70%'],
                        content: location.origin+"/webpack/src/pages/layer/setNote.html",
                        end:function () {
                            var img =document.getElementById("user_pciture");
                            img.style.backgroundImage="url("+JSON.parse(sessionStorage.user).picture+")"
                            $scope.listNote()
                        }
                    });
                };
                //笔记显示
                $scope.listNote = function () {
                    $http({
                        method:"post",
                        url:'/notes/listPage',
                        data:{data:{offset:0,limit:30}}
                    }).then(function(data) {
                        if(data.data.result)
                        {
                            $scope.noted=data.data.result.rows;
                        }else{
                            layer.alert("拉取数据失败")
                        }
                    }).catch(function(data) {
                        layer.alert('Request faile')
                    });
                }
                //编辑笔记
                $scope.setNote = function (d) {
                    sessionStorage.setItem('notes',JSON.stringify(d));
                    layer.open({
                        type: 2,
                        title: '修改笔记',
                        shadeClose: true,
                        shade: 1,
                        area: ['70%', '70%'],
                        content: location.origin+"/webpack/src/pages/layer/setNote.html",
                        end:function () {
                            var img =document.getElementById("user_pciture");
                            img.style.backgroundImage="url("+JSON.parse(sessionStorage.user).picture+")"
                            $scope.listNote()
                        }
                    });
                }
                $scope.listNote();
                //显示目录
                $scope.showNotelist = function (d) {
                    //添加目录
                    $scope.setWrapData.add( {"title":d.title,"templete":"ueditor",id:d.listid})
                    //改变目录
                    $scope.setTreeData.change(d.list)
                }
            }
        }
    });//定义指令，对应页面中的<hello-world></hello-world>
}